#pragma once

#include "Url.h"
#include "Containers/String.h"
#include "Containers/Map.h"
#include "Containers/Delegate.h"
#include "Containers/ThreadSafePtr.h"
#include "IPAddress.h"
#include "HttpRequestMethod.h"

class CTCPClient;
class CHttpResponse;

class CHttpRequest
{

public:

    void ProcessRequest();
    TDelegate<void,std::shared_ptr<CHttpResponse>> OnRequestFinished;

    EHttpRequestMethod Method = EHttpRequestMethod::GET;
    
    //request url , donot support parse domain name now
    CUrl Url;
    //do not need modify this in most cases
    CString HttpVersion = U"HTTP/1.1";
    
    //head begain ******************************************************

    void AddRawHead(const CString& Key, const CString& Value);
protected:
    TMap<CString, CString> HeadParameters;
    //head end ********************************************************

public:
    //only for POST
    CString Body;
protected:

    TOptional<SIPAddress> ParseHostName(const CString &HostName);

protected:
    TThreadSafeSharedPtr<CTCPClient> Socket;

};